package com.oms.app.user.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.oms.app.user.dao.IUserDAO;
import com.oms.app.user.model.User;
import com.oms.core.dao.impl.GeneralDAO;

/**
 * @author Loong_Mit
 * @date Sep 1, 2012 6:32:12 PM
 */

public class UserDAOImpl extends GeneralDAO<User, String> implements IUserDAO {
	@Override
	public User getUserByPK(int PK) {
		Map<String, String> param = new HashMap<String, String>();
		param.put("userId", String.valueOf(PK));
		return (User) this.queryForObject("getUserByCondition", param);
	}

	@Override
	public User getUserByRegName(String regname) {
		Map<String, String> param = new HashMap<String, String>();
		param.put("regName", regname);
		return (User) this.queryForObject("getUserByCondition", param);
	}

	@Override
	public User register(User regForm) {
		this.insert("insert", regForm);
		return (User) this.getUserByRegName(regForm.getRegname());
	}
	
	@Override
	public void addUser(User regForm) {
		this.insert(regForm);
	}
	
	@Override
	public User profile(User userForm) {
		this.update("profile", userForm);
		return (User) this.getUserByRegName(userForm.getRegname());
	}
	
	@Override
	public void updateUser(User userForm) {
		this.update("update", userForm);
	}
	
	@Override
	public List<User> getUserList(Map<String, Object> param) {
		param.put("order_type", "createtime");
		return (List<User>) this.queryForList("getUserByCondition", param);
	}
	
	@Override
	public int deleteUesr(int PK) {
		this.delete("delete", String.valueOf(PK));
		return 1;
	}

	@Override
	public boolean userAddRole(Map map) {
		this.insert("insertUserRole",map);
		return false;
	}

	@Override
	public boolean isUserRole(Map map) {
		int ct = this.getCount("isUserRole", map);
		return (ct > 0);
	}
//###################用户权限管理######################################################
	@Override
	public List getUserRole(User user) {
		return (List<User>) this.queryForList("getUserRole", user);
	}
	public List getUserModule(User user) {
		return (List<User>) this.queryForList("getUserModule", user);
	}
	public List getAllModule(){
		return (List<User>) this.queryForList("getAllModule");
	}

	@Override
	public boolean delUserRole(Map map) {
		this.delete("delUserRole", map);
		return false;
	}

	@Override
	public int delete(String primaryKey) {
		return 0;
	}

	@Override
	public User get(String primaryKey) {
		return null;
	}

	@Override
	public void insert(User entity) {
	}

	@Override
	public int update(User entity) {
		return 0;
	}

	@Override
	public int myShopId(int i) {
		Map map = new HashMap();
		map.put("usid", i+"");
		List list = this.queryForList("myShopId",map);
		if(list.size()==0){
			return 0;
		}else{
			return Integer.parseInt(((Map)list.get(0)).get("id").toString());
		}
		
	}
}
